var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [
		   {
			colkey : "outReceiptNo",
			name : "出仓单号"
		},
		{
			colkey : "no",
			name : "no"
		},{
			colkey : "tranDate",
			name : "日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		}, {
			colkey : "driverName",
			name : "司机"
		}, {
			colkey : "licenseNo",
			name : "车牌号"
			
		}, {
			colkey : "category",
			name : "物料/模具编号"
		},{
			colkey : "name",
			name : "客户"
		}, {
			colkey : "outReceiptNo",
			name : "送货单号",
			
		},{
			colkey : "handplayNumber",
			name : "手打单号"
		},{
			colkey : "number",
			name : "件数"
		},{
			colkey : "packNum",
			name : "包数"
		},{
			colkey : "Real",
			name : "实出"
		},{
			colkey : "fullCar",
			name : "满车率"
		},{
			colkey : "withCarpart",
			name : "跟车员"
		},{
			colkey : "carDate",
			name : "时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
		    colkey : "remake",
			name : "备注"
		},{
			colkey : "test",
			name : "检验"
		}],
		jsonUrl : rootPath + '/transportDispatch/transportDispatch_findbyPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#editFun").click("click", function() {
		editAccount();
	});
	$("#printing").click("click", function() {
		printingAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	$("#approval").click("click", function() {
		approvalAccount();
	});
	
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
	function editAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox.length > 1 ) {
			layer.msg("只能选中一个");
			return;
		}
		if(cbox == ""){
			layer.msg("需要选择一个");
			return;
		}
		pageii = layer.open({
			title : "编辑出厂放行",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transportDispatch/transportDispatch_approval2.shtml?id=' + cbox
		});
	}
	//审批
	function approvalAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox.length > 1 ) {
			layer.msg("只能选中一个");
			return;
		}
		if(cbox == ""){
			layer.msg("需要选择一个");
			return;
		}
		pageii = layer.open({
			title : "审批",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transportDispatch/transportDispatch_approval.shtml?id=' + cbox
			
		});
	}
	//打印
	function printingAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox.length > 1 ) {
			layer.msg("只能选中一个");
			return;
		}
		if(cbox == ""){
			layer.msg("需要选择一个");
			return;
		}
		pageii = layer.open({
			title : "打印",
			type : 2,
			area : [ "800px", "100%" ],
			//content : rootPath + '' + cbox
			
		});
	}
	
	
	function delAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox == "") {
			layer.msg("请选择删除项！！");
			return;
		}
		layer.confirm('是否删除？', function(index) {
			var url = rootPath + '/transportDispatch/transportDispatch_deleteEntity.shtml';
			var s = CommnUtil.ajax(url, {
				ids : cbox.join(",")
			}, "json");
			if (s == "success") {
				layer.msg('删除成功');
				grid.loadData();
			} else {
				layer.msg('删除失败');
			}
		});
	}
});